﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using NHibernate;
using SocialLearning;

/// <summary>
/// Summary description for Chat_Group
/// </summary>
public partial class Chat_Group_control
{
    public AMP_Group getGroup(int? GroupID)
    {
        // Open the session
        ISession session = NHibernateHelper.GetCurrentSession();

        // Load the Group from the database
        AMP_Group Group = (AMP_Group)session.Load(typeof(AMP_Group), GroupID);

        return Group;
    }

    public List<AMP_Group> getGroups()
    {
        List<AMP_Group> Groups = new List<AMP_Group>();

        // Open the session
        ISession session = NHibernateHelper.GetCurrentSession();

        // Load the Groups from the database
        session.CreateCriteria(typeof(AMP_Group)).List(Groups);

        return Groups;
    }

    public void saveOrUpdateGroup(AMP_Group Group)
    {
        ISession session = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = null;

        try
        {
            // Start transaction
            transaction = session.BeginTransaction();

            // Save or update (saves if the id is null, otherwise it updates)
            session.SaveOrUpdate(Group);

            // Commit transaction
            transaction.Commit();
        }
        catch (Exception ex)
        {
            transaction.Rollback();
            throw ex;
        }
    }

    public void deleteGroup(AMP_Group Group)
    {
        ISession session = NHibernateHelper.GetCurrentSession();
        ITransaction transaction = null;

        try
        {
            // Start transaction
            transaction = session.BeginTransaction();

            // Delete
            session.Delete(Group);

            // Commit transaction
            transaction.Commit();
        }
        catch (Exception ex)
        {
            transaction.Rollback();
            throw ex;
        }
    }
}


